<template>
	<!-- 修改密码 -->
	<div id="updatePwd">
		<van-nav-bar title="修改密码" fixed placeholder @click-left="$router.go(-1)" left-arrow></van-nav-bar>
		<div class="form">
			<div class="form-item">
				<div class="label">原密码</div>
				<input type="password" v-model="form.oldPwd">
			</div>
			<div class="form-item">
				<div class="label">新密码</div>
				<input type="password" v-model="form.newPwd">
			</div>
			<div class="form-item">
				<div class="label">确认密码</div>
				<input type="password" v-model="form.requiredPwd">
			</div>
		</div>
		<div class="submit" @click="submitForm">提交</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					oldPwd:"",
					newPwd:"",
					requiredPwd:""
				}
			}
		},
		methods:{
			checkFun(form){
				for(let key in form){
					if(!form[key]){
						return false
					}
				}
				return true
			},
			//提交表单修改密码
			async submitForm(){
				if(this.checkFun(this.form)){
					const reqParams={}
					// 使用md5对密码进行加密
					for(let key in this.form){
						reqParams[key]=this.md5(this.form[key])
					}
					const results=await this.$store.dispatch("userUpdatePwd",reqParams)
					if(results.code==0){
						this.$dialog.alert({
							message:"修改成功",
							confirmButtonColor:"#25987D"
						})
					}else {
						this.$dialog.alert({
							message:results.msg,
							confirmButtonColor:"#25987D"
						})
					}
				}else {
					this.$dialog.alert({
						message:"表单信息不能为空",
						confirmButtonText:"去填写",
						confirmButtonColor:"#25987D"
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
@import "../../scss/GLOBAL.scss";
#updatePwd {
	user-select: none;
	::v-deep {
		.van-nav-bar {
			background-color: $themeColor;
			.van-nav-bar__title {
				color: #fff;
			}
			.van-icon {
				color: #fff;
			}
		} 
	}
	.form {
		padding: 0 1.25em;
		.form-item {
			display: flex;
			align-items: center;
			margin: 0.625em 0;
			.label {
				flex-basis: 5em;
				font-size: .9em;
			}
			input {
				flex: 1;
				padding: .325em 1.25em;
				border-radius:.25em;
			}
		}
	}
	.submit {
		text-align: center;
		background-color: $themeColor;
		color: #fff;
		padding: 0.625em 0;
	}
}
</style>